﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Plugin
{
    public partial class frmConfig : Form
    {
        public frmConfig()
        {
            InitializeComponent();
        }

        private void frmConfig_Load(object sender, EventArgs e)
        {
            iniComboBox();
            ReadConfig();
        }

        private void iniComboBox()
        {
            cmbPrinters.Items.Clear();
            foreach (string strTmp in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
            {
                cmbPrinters.Items.Add(strTmp);
            }
        }

        private void ReadConfig()
        {
            StringBuilder tmpsb = new StringBuilder();
            GeneralTools.GetPrivateProfileString("Config", "Printer", string.Empty, tmpsb, 256, Application.StartupPath + "\\Plugin\\Print_Zxysd_33_Config.ini");
            if (!tmpsb.ToString ().Equals (string.Empty ))
            {
                cmbPrinters.Text = tmpsb.ToString();
            }
            GeneralTools.GetPrivateProfileString("Config", "CopyCount", string.Empty, tmpsb, 256, Application.StartupPath + "\\Plugin\\Print_Zxysd_33_Config.ini");
            if (tmpsb.ToString().Equals(string.Empty))
            {
                nudCopy.Value = 1;
            }
            else
            {
                nudCopy.Value = Plugin.GeneralTools.GetInt(tmpsb.ToString(),1);
            }
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            GeneralTools.WritePrivateProfileString("Config", "Printer", cmbPrinters.Text, Application.StartupPath + "\\Plugin\\Print_Zxysd_33_Config.ini");
            GeneralTools.WritePrivateProfileString("Config", "CopyCount",nudCopy .Value .ToString (), Application.StartupPath + "\\Plugin\\Print_Zxysd_33_Config.ini");
            GeneralTools.ShowInfoMsg("设置保存成功！");
            this.Close();
        }
    }
}
